package com.douyu.data.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.MessageSourceResourceBundle;
import org.springframework.context.support.ResourceBundleMessageSource;

import javax.annotation.Resource;
import java.util.Locale;
import java.util.spi.ResourceBundleControlProvider;

public class Resources {
    private static final Logger logger = LoggerFactory.getLogger(Resources.class);
    private static final ResourceBundleMessageSource SOURCE = new ResourceBundleMessageSource();

    static {
        logger.info("===Resources===");
        try{
            SOURCE.setBasename("resources");
            SOURCE.setDefaultEncoding(Constant.DEFAULT_ENCODING);
        } catch (Exception e){
            logger.error("遇到了问题：" + e);
        }
    }
    public static String getProperty(String code){
      return SOURCE.getMessage(code, null, Locale.getDefault());
    }

    public static String getProperty(String code, String[] args){
        return SOURCE.getMessage(code, args, Locale.getDefault());
    }
}

